home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-08 | 69.2 KB | 2,887 lines | [TEXT/CWIE] |
- //
- // GrayCouncilPP
- // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
- //
- // PowerPlant adapter classes for core Gray Council.
- //
- // Before using any of the GrayCouncil source code, read and
- // follow the licensing info in the accompanying documentation
- // or contact:
- // <trygve@kagi.com>
- // <http://www.kagi.com/authors/trygve/>
- //
- // GrayCouncil provides a set of standard C++ classes that implement
- // the standard Apple Grayscale Appearance. The core classes do not
- // require any other code such as a particular class framework.
- //
- // This file defines a set of helper classes that derive from standard
- // PowerPlant pane classes, and interface with the core Gray Council code.
- // There are also a couple of attachment subclasses for attaching to
- // other pane classes to get a white background and 3D frame.
- //
- // Normally, to use a GrayCouncil PowerPlant class, you can simply change the
- // class ID of the pane in your Constructor window resource to the
- // class ID of the appropriate Gray Council PowerPlant adapter class. For
- // example, to use the GC pushbutton, create a normal LButton pane,
- // and set its class ID to 'GCpb'. Voila. This also works for the LAttachment
- // subclasses defined here.
- //
- // A couple of the classes use the mUserCon field of the subview to specify
- // additional information such as icon IDs, string resource IDs, etc.
- //
- // If the mUserCon usage conflicts with what you are already doing with it,
- // you can use the "extended" pane subclasses (those whose class name ends
- // in "PPX" instead of "PP"). These classes read their additional info from
- // the pane resource stream instead of using mUserCon. In some cases they
- // let you specify additional options in the pane resource that you would
- // otherwise have to specify programmatically. The supplied resource file
- // named GCCustomPanes.rsrc contains the 'CPPb' custom pane definitions.
- // If you put this file in the Constructor app's folder, or keep it open
- // whenever your pane resource file is open, or paste the custom pane
- // types into your pane resource file, you can use the extended pane classes
- // in Constructor.
- //
- // Each class here that interfaces to a core AGAObject has a public
- // member variable called mAGAObject that points to the actual AGAObject
- // subclass object. Certain extended object settings (such as mixed-state
- // buttons, proportional and live scrolling, etc.) require you to call
- // the AGAObject to set it. The member variable is made public to keep
- // these MacApp classes as lightweight as possible; you make the call,
- // rather than using myriad new functions of the PowerPlant AGA subclasses.
- //
- // Classes defined below:
- // AGAWindowPP -- LWindow subclass that draws a modeless window gray
- // background.
- // AGADialogBoxPP -- LDialogBox subclass that draws a modal window gray
- // background and replaces the PowerPlant default button outline by
- // altering the style of the default button AGAPushButton object.
- // AGAPushButtonPP -- LStdButton subclass for AGAPushButton.
- // AGACheckBoxPP -- LStdCheckBox subclass for AGACheckBox.
- // AGARadioButtonPP -- LStdRadioButton subclass for AGARadioButton.
- // AGAIconPushButtonPP -- AGAPushButtonPP (LStdButton) subclass for
- // AGAIconPushButton.
- // AGAIconPushButtonPPX -- AGAIconPushButtonPP (LStdButton) subclass for
- // AGAIconPushButton, that uses extended CPPb data for the icon ID.
- // AGAIconCheckBoxPP -- AGACheckBoxPP (LStdCheckBox) subclass for
- // AGAIconCheckBox.
- // AGAIconCheckBoxPPX -- AGAIconCheckBoxPP (LStdCheckBox) subclass for
- // AGAIconCheckBox, that uses extended CPPb data for the icon IDs.
- // AGAIconRadioButtonPP -- AGARadioButtonPP (LStdRadioButton) subclass
- // for AGAIconRadioButton.
- // AGAIconRadioButtonPPX -- AGAIconRadioButtonPP (LStdRadioButton) subclass
- // for AGAIconRadioButton, that uses extended CPPb data for the icon IDs.
- // AGAIconRadioButtonMA -- AGARadioButtonMA (LStdRadioButton) subclass for
- // AGAIconRadioButton.
- // AGAGroupBoxPP -- LGroupBox subclass for AGAGroupBox, with primary group
- // box appearance.
- // AGAGroupBoxPPX -- AGAGroupBoxPP (LGroupBox) subclass for AGAGroupBox,
- // that uses extended CPPb data for the box type and gap pane ID.
- // AGASecondaryGroupBoxPP -- AGAGroupBoxPP (LGroupBox) subclass for
- // AGAGroupBox, with secondary group box appearance.
- // AGAScrollBarPP -- LStdControl subclass for AGAScrollBar.
- // AGAScrollerPP -- LScroller subclass that replaces the normal LStdControl
- // scroll bars with ones of class AGAScrollBarPP, and correctly
- // maintain them during scrolling.
- // AGASliderPP -- LControl subclass for AGASlider.
- // AGASliderPPX -- AGASliderPP (LControl) subclass for AGASlider, that
- // uses extended CPPb data for the label strings ID, style, and
- // slider justification.
- // AGALittleArrowsPP -- LControl subclass for AGALittleArrows.
- // AGALittleArrowsPPX -- AGALittleArrowsPP (LControl) subclass for
- // AGALittleArrows, that uses extended CPPb data for the linked
- // numeric LEditField pane ID.
- // AGAPopupMenuPP -- LStdPopupMenu subclass for AGAPopupMenu.
- // AGADisclosureTrianglePP -- LControl subclass for AGADisclosureTriangle.
- // AGAProgressIndicatorPP -- LControl subclass for AGAProgressIndicator.
- // AGAWhiteBackgroundAttachmentPP -- LAttachment subclass that draws a
- // white background for the pane to which it is attached.
- // AGABorderFrameAttachmentPP -- LAttachment subclass that draws a
- // "3D" sunken frame around the pane to which it is attached.
- // AGAEditFieldPP -- LEditField subclass that automatically attaches an
- // AGAWhiteBackgroundAttachmentPP and an AGABorderFrameAttachmentPP,
- // and also knows how to draw the frame in disabled gray when disabled.
- // AGATextEditPP -- LTextEdit subclass that automatically attaches an
- // AGAWhiteBackgroundAttachmentPP and an AGABorderFrameAttachmentPP.
- // AGASeparatorPP -- LPane subclass for AGASeparator.
- // AGACaptionPP -- LCaption subclass for AGAStaticText.
- // AGAFocusBoxPP -- LFocusBox subclass used by AGAListBox to draw the
- // list box focus frame.
- // AGAListBoxPP -- LListBox subclass that automatically attaches an
- // AGAWhiteBackgroundAttachmentPP and an AGABorderFrameAttachmentPP,
- // and also replaces the normal LFocusBox with an AGAFocusBoxPP so
- // that the focus frame appears correct.
- //
-
- #include "GrayCouncilPP.h"
-
- // There are 3 places in this file that use run-time type
- // information (RTTI). This requires turning on the RTTI switch
- // in the CodeWarrior C/C++ Language preferences panel. If for
- // some reason you can't do this, simply #define NO_RTTI here
- // and the RTTI-dependent code will be skipped. But if you do
- // this, check the comments below where the RTTI usage is so
- // that you don't violate the constraints that the RTTI usage
- // was checking for.
-
- #ifndef NO_RTTI
- #include <typeinfo.h>
- #endif // NO_RTTI
-
- // The URegistrar::RegisterClass calls are making my eyes hurt.
- // Define a macro to do it instead. We take advantage of the fact that
- // we use the names class_ID and CreateStream in all of our classes.
- #define GCPP_REGISTER_CLASS(classname) URegistrar::RegisterClass(classname::class_ID, (ClassCreatorFunc) classname::CreateStream)
-
- OSErr InitGrayCouncilPP()
- {
- //
- // Register our dynamically instantiated pane & attachment subclasses.
- //
-
- GCPP_REGISTER_CLASS(AGAWhiteBackgroundAttachmentPP);
- GCPP_REGISTER_CLASS(AGABorderFrameAttachmentPP);
- GCPP_REGISTER_CLASS(AGAWindowPP);
- GCPP_REGISTER_CLASS(AGADialogBoxPP);
- GCPP_REGISTER_CLASS(AGAPushButtonPP);
- GCPP_REGISTER_CLASS(AGACheckBoxPP);
- GCPP_REGISTER_CLASS(AGARadioButtonPP);
- GCPP_REGISTER_CLASS(AGAIconPushButtonPP);
- GCPP_REGISTER_CLASS(AGAIconPushButtonPPX);
- GCPP_REGISTER_CLASS(AGAIconCheckBoxPP);
- GCPP_REGISTER_CLASS(AGAIconCheckBoxPPX);
- GCPP_REGISTER_CLASS(AGAIconRadioButtonPP);
- GCPP_REGISTER_CLASS(AGAIconRadioButtonPPX);
- GCPP_REGISTER_CLASS(AGAScrollBarPP);
- GCPP_REGISTER_CLASS(AGAScrollerPP);
- GCPP_REGISTER_CLASS(AGAGroupBoxPP);
- GCPP_REGISTER_CLASS(AGAGroupBoxPPX);
- GCPP_REGISTER_CLASS(AGASecondaryGroupBoxPP);
- GCPP_REGISTER_CLASS(AGASliderPP);
- GCPP_REGISTER_CLASS(AGASliderPPX);
- GCPP_REGISTER_CLASS(AGALittleArrowsPP);
- GCPP_REGISTER_CLASS(AGALittleArrowsPPX);
- GCPP_REGISTER_CLASS(AGAPopupMenuPP);
- GCPP_REGISTER_CLASS(AGADisclosureTrianglePP);
- GCPP_REGISTER_CLASS(AGAProgressIndicatorPP);
- GCPP_REGISTER_CLASS(AGAEditFieldPP);
- GCPP_REGISTER_CLASS(AGATextEditPP);
- GCPP_REGISTER_CLASS(AGASeparatorPP);
- GCPP_REGISTER_CLASS(AGAListBoxPP);
- GCPP_REGISTER_CLASS(AGAFocusBoxPP);
- GCPP_REGISTER_CLASS(AGACaptionPP);
-
- // Do Core Gray Council initialization.
- return InitGrayCouncil();
- }
-
- static SInt32 MinSInt32(SInt32 a, SInt32 b) { return (a < b) ? a : b; }
- static SInt32 MaxSInt32(SInt32 a, SInt32 b) { return (a > b) ? a : b; }
-
- static SInt32 GetTextTraitsJustification(ResIDT inTextTraitsID)
- {
- TextTraitsH aTTHandle = UTextTraits::LoadTextTraits(inTextTraitsID);
-
- if (aTTHandle == NULL)
- return teFlushDefault;
- else
- return (**aTTHandle).justification;
- }
-
- //
- // AGAWindowPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LWindow
-
- AGAWindowPP* AGAWindowPP::CreateStream(LStream* inStream)
- {
- return new AGAWindowPP(inStream);
- }
-
- AGAWindowPP::AGAWindowPP(LStream* inStream)
- : Inherited(inStream)
- {
- }
-
- AGAWindowPP::~AGAWindowPP()
- {
- }
-
- void AGAWindowPP::FinishCreate()
- {
- // Make sure that the gray background color is installed
- // prior to subpanes having their FinishCreateSelf method
- // called.
-
- this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
-
- Inherited::FinishCreate();
- }
-
- void AGAWindowPP::FinishCreateSelf()
- {
- // Let LWindow do its normal stuff first.
-
- Inherited::FinishCreateSelf();
-
- // Install gray background color.
- this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
- }
-
- void AGAWindowPP::DrawSelf()
- {
- // Change normal DrawSelf by drawing our background.
-
- if (HasAttribute(windAttr_EraseOnUpdate))
- this->DrawBackground(&mMacWindowP->portRect, TRUE, mActive == triState_On);
-
- this->DrawSizeBox();
- }
-
- void AGAWindowPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
- {
- // If the window size is changing in either direction, we need
- // to invalidate the right/bottom edge pixels that will
- // need to turn gray when the window is expanded, either before
- // or after the resize.
-
- this->InvalidateEdges(TRUE, inWidthDelta, inHeightDelta);
-
- Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
-
- this->InvalidateEdges(FALSE, inWidthDelta, inHeightDelta);
- }
-
- void AGAWindowPP::ActivateSelf()
- {
- // Redraw just the edge pixels that change based on active state.
-
- this->FocusDraw();
- this->DrawBackground(&mMacWindowP->portRect, FALSE, TRUE);
-
- Inherited::ActivateSelf();
- }
-
- void AGAWindowPP::DeactivateSelf()
- {
- // Redraw just the edge pixels that change based on active state.
-
- this->FocusDraw();
- this->DrawBackground(&mMacWindowP->portRect, FALSE, FALSE);
-
- Inherited::DeactivateSelf();
- }
-
- void AGAWindowPP::DrawBackground(const Rect* area, Boolean fill, Boolean active)
- {
- AGABackgroundPaint(area, fill, kIsNotModal, active, (mAttributes & windAttr_SizeBox) != 0);
- }
-
- void AGAWindowPP::InvalidateEdges(Boolean before, Int16 inWidthDelta, Int16 inHeightDelta)
- {
- // Invalidate the extra "edge" pixels that need to be redrawn
- // when the window is resized.
-
- Rect bounds;
- Rect rectToInvalidate;
-
- this->CalcPortFrameRect(bounds);
-
- if (((inWidthDelta > 0) && before) ||
- ((inWidthDelta < 0) && ! before))
- {
- rectToInvalidate = bounds;
- rectToInvalidate.left = rectToInvalidate.right - 1;
- this->InvalPortRect(&rectToInvalidate);
- }
-
- if (((inHeightDelta > 0) && before) ||
- ((inHeightDelta < 0) && ! before))
- {
- rectToInvalidate = bounds;
- rectToInvalidate.top = rectToInvalidate.bottom - 1;
- this->InvalPortRect(&rectToInvalidate);
- }
-
- if ((mAttributes & windAttr_SizeBox) != 0)
- {
- rectToInvalidate = bounds;
- rectToInvalidate.left = rectToInvalidate.right - 16;
- rectToInvalidate.top = rectToInvalidate.bottom - 16;
- this->InvalPortRect(&rectToInvalidate);
- }
- }
-
- //
- // AGADialogBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LDialogBox
-
- AGADialogBoxPP* AGADialogBoxPP::CreateStream(LStream* inStream)
- {
- return new AGADialogBoxPP(inStream);
- }
-
- AGADialogBoxPP::AGADialogBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- mDeleteDefaultOutline = FALSE;
- }
-
- AGADialogBoxPP::~AGADialogBoxPP()
- {
- }
-
- void AGADialogBoxPP::FinishCreate()
- {
- // Make sure that the gray background color is installed
- // prior to subpanes having their FinishCreateSelf method
- // called.
-
- this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
-
- Inherited::FinishCreate();
- }
-
- void AGADialogBoxPP::FinishCreateSelf()
- {
- // Let LDialogBox do its normal stuff first.
-
- Inherited::FinishCreateSelf();
-
- // Install gray background color.
- this->SetForeAndBackColors(NULL, &gAGARamp[r2]);
-
- //
- // Now we remove its LDefaultOutline and set the
- // default our way.
- //
-
- if (mDefaultOutline != NULL)
- {
- delete mDefaultOutline;
- mDefaultOutline = NULL;
- }
-
- this->SetDefaultButton(mDefaultButtonID);
- }
-
- void AGADialogBoxPP::SetDefaultButton(PaneIDT inButtonID)
- {
- // If you bypass the RTTI here, you must ensure that the
- // panes represented by the mDefaultButtonID and the
- // inButtonID are subclass of AGAPushButtonPP.
-
- AGAPushButtonPP* oldDefaultButton = NULL;
- AGAPushButtonPP* newDefaultButton = NULL;
- LPane* oldDefaultPane = this->FindPaneByID(mDefaultButtonID);
- LPane* newDefaultPane = this->FindPaneByID(inButtonID);
-
- #ifndef NO_RTTI
-
- if (oldDefaultPane != NULL)
- oldDefaultButton = dynamic_cast<AGAPushButtonPP*>(oldDefaultPane);
-
- if (newDefaultPane != NULL)
- newDefaultButton = dynamic_cast<AGAPushButtonPP*>(newDefaultPane);
-
- #else // NO_RTTI
-
- oldDefaultButton = (AGAPushButtonPP*) oldDefaultPane;
- newDefaultButton = (AGAPushButtonPP*) newDefaultPane;
-
- #endif // NO_RTTI
-
- mDefaultButtonID = inButtonID;
-
- if (oldDefaultButton != NULL)
- {
- // Tell the old default button that it is no longer
- // the default.
-
- oldDefaultButton->mAGAObject->SetDefault(AGAObject::kIsNotDefault, AGAObject::kFrameOutside);
- oldDefaultButton->Refresh();
- }
- else if (mDefaultOutline != nil)
- {
- // Not an AGA object. Do it the LDialogBox way...
-
- mDefaultOutline->Refresh();
- delete mDefaultOutline;
- mDefaultOutline = NULL;
- }
-
- if (newDefaultButton != NULL)
- {
- // Tell the new default button that it has become
- // the default.
-
- newDefaultButton->mAGAObject->SetDefault(AGAObject::kIsDefault, AGAObject::kFrameOutside);
- newDefaultButton->Refresh();
- }
- else if (newDefaultPane != NULL)
- {
- // Not an AGA object. Do it the LDialogBox way...
-
- ((LControl*) newDefaultPane)->AddListener(this);
- mDefaultOutline = new LDefaultOutline(newDefaultPane);
- mDefaultOutline->Refresh();
- }
- }
-
- void AGADialogBoxPP::DrawSelf()
- {
- // Change normal DrawSelf by drawing our background.
-
- if (HasAttribute(windAttr_EraseOnUpdate))
- this->DrawBackground(&mMacWindowP->portRect, TRUE, mActive == triState_On);
-
- this->DrawSizeBox();
- }
-
- void AGADialogBoxPP::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
- {
- // If the window size is changing in either direction, we need
- // to invalidate the right/bottom edge pixels that will
- // need to turn gray when the window is expanded, either before
- // or after the resize.
-
- this->InvalidateEdges(TRUE, inWidthDelta, inHeightDelta);
-
- Inherited::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
-
- this->InvalidateEdges(FALSE, inWidthDelta, inHeightDelta);
- }
-
- void AGADialogBoxPP::ActivateSelf()
- {
- // Redraw just the edge pixels that change based on active state.
-
- this->FocusDraw();
- this->DrawBackground(&mMacWindowP->portRect, FALSE, TRUE);
-
- Inherited::ActivateSelf();
- }
-
- void AGADialogBoxPP::DeactivateSelf()
- {
- // Redraw just the edge pixels that change based on active state.
-
- this->FocusDraw();
- this->DrawBackground(&mMacWindowP->portRect, FALSE, FALSE);
-
- Inherited::DeactivateSelf();
- }
-
- void AGADialogBoxPP::DrawBackground(const Rect* area, Boolean fill, Boolean active)
- {
- AGABackgroundPaint(area, fill, kIsModal, active, (mAttributes & windAttr_SizeBox) != 0);
- }
-
- void AGADialogBoxPP::InvalidateEdges(Boolean before, Int16 inWidthDelta, Int16 inHeightDelta)
- {
- // Invalidate the extra "edge" pixels that need to be redrawn
- // when the window is resized.
-
- Rect bounds;
- Rect rectToInvalidate;
-
- this->CalcPortFrameRect(bounds);
-
- if (((inWidthDelta > 0) && before) ||
- ((inWidthDelta < 0) && ! before))
- {
- rectToInvalidate = bounds;
- rectToInvalidate.left = rectToInvalidate.right - 1;
- this->InvalPortRect(&rectToInvalidate);
- }
-
- if (((inHeightDelta > 0) && before) ||
- ((inHeightDelta < 0) && ! before))
- {
- rectToInvalidate = bounds;
- rectToInvalidate.top = rectToInvalidate.bottom - 1;
- this->InvalPortRect(&rectToInvalidate);
- }
-
- if ((mAttributes & windAttr_SizeBox) != 0)
- {
- rectToInvalidate = bounds;
- rectToInvalidate.left = rectToInvalidate.right - 16;
- rectToInvalidate.top = rectToInvalidate.bottom - 16;
- this->InvalPortRect(&rectToInvalidate);
- }
- }
-
- //
- // AGAPushButtonPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LStdButton
-
- AGAPushButtonPP* AGAPushButtonPP::CreateStream(LStream* inStream)
- {
- return new AGAPushButtonPP(inStream);
- }
-
- AGAPushButtonPP::AGAPushButtonPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGAPushButtonPP::~AGAPushButtonPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGAPushButtonPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->HideSelf(); // make sure the Control Manager object is not drawn
-
- this->CreateAGAObject();
- }
-
- void AGAPushButtonPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGAPushButtonPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGAPushButtonPP::HotSpotAction(SInt16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside)
- {
- // Draw the button based on the new press state.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->DrawButton(inCurrInside);
- }
- }
-
- void AGAPushButtonPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGAPushButtonPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGAPushButtonPP::ShowSelf()
- {
- // Suppress showing the Control Manager control.
- }
-
- void AGAPushButtonPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
- Str255 title;
-
- (void) this->CalcLocalFrameRect(bounds);
- ::GetControlTitle(mMacControlH, title);
-
- ThrowIfNil_(mAGAObject = new AGAPushButton(&bounds, AGATextStyle(mTextTraitsID), title));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
- }
-
- //
- // AGACheckBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LStdCheckBox
-
- AGACheckBoxPP* AGACheckBoxPP::CreateStream(LStream* inStream)
- {
- return new AGACheckBoxPP(inStream);
- }
-
- AGACheckBoxPP::AGACheckBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGACheckBoxPP::~AGACheckBoxPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGACheckBoxPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->HideSelf(); // make sure the Control Manager object is not drawn
-
- this->CreateAGAObject();
- }
-
- void AGACheckBoxPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGACheckBoxPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGACheckBoxPP::HotSpotAction(SInt16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside)
- {
- // Draw the button based on the new press state.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->DrawButton(inCurrInside);
- }
- }
-
- void AGACheckBoxPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGACheckBoxPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGACheckBoxPP::ShowSelf()
- {
- // Suppress showing the Control Manager control.
- }
-
- void AGACheckBoxPP::SetValue(SInt32 inValue)
- {
- // Set the actual LControl value and the AGA object value.
-
- Inherited::SetValue(inValue);
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetValue(inValue, AGAObject::kRedraw);
- }
- }
-
- void AGACheckBoxPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
- Str255 title;
-
- (void) this->CalcLocalFrameRect(bounds);
- ::GetControlTitle(mMacControlH, title);
-
- ThrowIfNil_(mAGAObject = new AGACheckBox(&bounds, AGATextStyle(mTextTraitsID), title, AGAObject::kNoAutomaticState));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
- }
-
- //
- // AGARadioButtonPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LStdRadioButton
-
- AGARadioButtonPP* AGARadioButtonPP::CreateStream(LStream* inStream)
- {
- return new AGARadioButtonPP(inStream);
- }
-
- AGARadioButtonPP::AGARadioButtonPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGARadioButtonPP::~AGARadioButtonPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGARadioButtonPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->HideSelf(); // make sure the Control Manager object is not drawn
-
- this->CreateAGAObject();
- }
-
- void AGARadioButtonPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGARadioButtonPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGARadioButtonPP::HotSpotAction(SInt16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside)
- {
- // Draw the button based on the new press state.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->DrawButton(inCurrInside);
- }
- }
-
- void AGARadioButtonPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGARadioButtonPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGARadioButtonPP::ShowSelf()
- {
- // Suppress showing the Control Manager control.
- }
-
- void AGARadioButtonPP::SetValue(SInt32 inValue)
- {
- // Set the actual LControl value and the AGA object value.
-
- Inherited::SetValue(inValue);
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetValue(inValue, AGAObject::kRedraw);
- }
- }
-
- void AGARadioButtonPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
- Str255 title;
-
- (void) this->CalcLocalFrameRect(bounds);
- ::GetControlTitle(mMacControlH, title);
-
- ThrowIfNil_(mAGAObject = new AGARadioButton(&bounds, AGATextStyle(mTextTraitsID), title, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
- }
-
- //
- // AGAIconPushButtonPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGAPushButtonPP
-
- AGAIconPushButtonPP* AGAIconPushButtonPP::CreateStream(LStream* inStream)
- {
- return new AGAIconPushButtonPP(inStream);
- }
-
- AGAIconPushButtonPP::AGAIconPushButtonPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Use the mUserCon for the icon ID.
-
- mIconID = mUserCon;
- }
-
- AGAIconPushButtonPP::~AGAIconPushButtonPP()
- {
- }
-
- void AGAIconPushButtonPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAIconPushButton(&bounds, mIconID, MIconButtonObject::GetDefaultIconType(bounds.right - bounds.left)));
- }
-
- //
- // AGAIconPushButtonPPX ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGAIconPushButtonPP
-
- AGAIconPushButtonPPX* AGAIconPushButtonPPX::CreateStream(LStream* inStream)
- {
- return new AGAIconPushButtonPPX(inStream);
- }
-
- AGAIconPushButtonPPX::AGAIconPushButtonPPX(LStream* inStream)
- : Inherited(inStream)
- {
- // Read the icon ID from the stream.
-
- inStream->ReadData(&mIconID, sizeof(mIconID));
- }
-
- AGAIconPushButtonPPX::~AGAIconPushButtonPPX()
- {
- }
-
- //
- // AGAIconCheckBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGACheckBoxPP
-
- AGAIconCheckBoxPP* AGAIconCheckBoxPP::CreateStream(LStream* inStream)
- {
- return new AGAIconCheckBoxPP(inStream);
- }
-
- AGAIconCheckBoxPP::AGAIconCheckBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Use the mUserCon for both icon IDs.
-
- mOffIconID = mUserCon;
- mOnIconID = mUserCon;
- }
-
- AGAIconCheckBoxPP::~AGAIconCheckBoxPP()
- {
- }
-
- void AGAIconCheckBoxPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAIconCheckBox(&bounds, AGAObject::kNoAutomaticState, mOffIconID, mOnIconID, MIconButtonObject::GetDefaultIconType(bounds.right - bounds.left)));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
- }
-
- //
- // AGAIconCheckBoxPPX ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGAIconCheckBoxPP
-
- AGAIconCheckBoxPPX* AGAIconCheckBoxPPX::CreateStream(LStream* inStream)
- {
- return new AGAIconCheckBoxPPX(inStream);
- }
-
- AGAIconCheckBoxPPX::AGAIconCheckBoxPPX(LStream* inStream)
- : Inherited(inStream)
- {
- // Read the icon IDs from the stream.
-
- inStream->ReadData(&mOffIconID, sizeof(mOffIconID));
- inStream->ReadData(&mOnIconID, sizeof(mOnIconID));
- }
-
- AGAIconCheckBoxPPX::~AGAIconCheckBoxPPX()
- {
- }
-
- //
- // AGAIconRadioButtonPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGARadioButtonPP
-
- AGAIconRadioButtonPP* AGAIconRadioButtonPP::CreateStream(LStream* inStream)
- {
- return new AGAIconRadioButtonPP(inStream);
- }
-
- AGAIconRadioButtonPP::AGAIconRadioButtonPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Use the mUserCon for both icon IDs.
-
- mOffIconID = mUserCon;
- mOnIconID = mUserCon;
- }
-
- AGAIconRadioButtonPP::~AGAIconRadioButtonPP()
- {
- }
-
- void AGAIconRadioButtonPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAIconRadioButton(&bounds, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState, mOffIconID, mOnIconID, MIconButtonObject::GetDefaultIconType(bounds.right - bounds.left)));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- mAGAObject->SetValue(this->GetValue(), AGAObject::kDontRedraw);
- }
-
- //
- // AGAIconRadioButtonPPX ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGAIconRadioButtonPP
-
- AGAIconRadioButtonPPX* AGAIconRadioButtonPPX::CreateStream(LStream* inStream)
- {
- return new AGAIconRadioButtonPPX(inStream);
- }
-
- AGAIconRadioButtonPPX::AGAIconRadioButtonPPX(LStream* inStream)
- : Inherited(inStream)
- {
- // Read the icon IDs from the stream.
-
- inStream->ReadData(&mOffIconID, sizeof(mOffIconID));
- inStream->ReadData(&mOnIconID, sizeof(mOnIconID));
- }
-
- AGAIconRadioButtonPPX::~AGAIconRadioButtonPPX()
- {
- }
-
- //
- // AGAGroupBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LGroupBox
-
- AGAGroupBoxPP* AGAGroupBoxPP::CreateStream(LStream* inStream)
- {
- return new AGAGroupBoxPP(inStream);
- }
-
- AGAGroupBoxPP::AGAGroupBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Assume primary group type, and use the mUserCon as the
- // gap pane's ID.
-
- mAGAObject = NULL;
- mIsPrimaryGroup = TRUE;
- mGapPaneID = mUserCon;
- }
-
- AGAGroupBoxPP::~AGAGroupBoxPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGAGroupBoxPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGAGroupBoxPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGAGroupBoxPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGAGroupBoxPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGAGroupBoxPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAGroupBox(&bounds, AGATextStyle(mTxtrID), mIsPrimaryGroup, mText));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- if ((mGapPaneID != 0) && (this->GetSuperView() != NULL))
- {
- LPane* gapPane = this->GetSuperView()->FindPaneByID(mGapPaneID);
-
- if (gapPane != NULL)
- {
- Rect bounds;
-
- (void) gapPane->CalcLocalFrameRect(bounds);
-
- mAGAObject->SetTitleGap(5 + bounds.right - bounds.left);
- }
- }
- }
-
- //
- // AGAGroupBoxPPX ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGAGroupBoxPP
-
- AGAGroupBoxPPX* AGAGroupBoxPPX::CreateStream(LStream* inStream)
- {
- return new AGAGroupBoxPPX(inStream);
- }
-
- AGAGroupBoxPPX::AGAGroupBoxPPX(LStream* inStream)
- : Inherited(inStream)
- {
- // Read the group type and gap pane ID from the stream.
-
- inStream->ReadData(&mIsPrimaryGroup, sizeof(mIsPrimaryGroup));
- inStream->ReadData(&mGapPaneID, sizeof(mGapPaneID));
- }
-
- AGAGroupBoxPPX::~AGAGroupBoxPPX()
- {
- }
-
- //
- // AGASecondaryGroupBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGAGroupBoxPP
-
- AGASecondaryGroupBoxPP* AGASecondaryGroupBoxPP::CreateStream(LStream* inStream)
- {
- return new AGASecondaryGroupBoxPP(inStream);
- }
-
- AGASecondaryGroupBoxPP::AGASecondaryGroupBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Set to secondary group box type. Will be used when AGA object
- // is created.
-
- mIsPrimaryGroup = FALSE;
- }
-
- AGASecondaryGroupBoxPP::~AGASecondaryGroupBoxPP()
- {
- }
-
- //
- // AGAScrollBarPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LStdControl
-
- AGAScrollBarPP* AGAScrollBarPP::CreateStream(LStream* inStream)
- {
- return new AGAScrollBarPP(inStream);
- }
-
- AGAScrollBarPP::AGAScrollBarPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- mNotificationRoutine = NULL;
- mUserData = 0;
- }
-
- AGAScrollBarPP::AGAScrollBarPP(const SPaneInfo &inPaneInfo,
- MessageT inValueMessage,
- Int32 inValue,
- Int32 inMinValue,
- Int32 inMaxValue,
- Int16 inControlKind,
- ResIDT inTextTraitsID,
- Str255 inTitle,
- Int32 inMacRefCon)
- : Inherited(inPaneInfo, inValueMessage, inValue, inMinValue, inMaxValue, inControlKind, inTextTraitsID, inTitle, inMacRefCon)
- {
- mAGAObject = NULL;
- mNotificationRoutine = NULL;
- mUserData = 0;
- }
-
- AGAScrollBarPP::~AGAScrollBarPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGAScrollBarPP::InstallNotificationRoutine(AGANotifyPPPtr notificationRoutine, void* userData)
- {
- // Save the notification routine fn pointer and user data
- // for notification handling.
-
- mNotificationRoutine = notificationRoutine;
- mUserData = userData;
- }
-
- void AGAScrollBarPP::HandleNotification(SInt32 dataValue)
- {
- // Update the scrollbar value, call the installed notification
- // function, and propagate our event number.
-
- this->SetValue(dataValue);
-
- if (mNotificationRoutine != NULL)
- (*mNotificationRoutine)(this, dataValue, mUserData);
-
- this->BroadcastValueMessage();
-
- (void) this->FocusDraw(); // HandleEvent may have caused another view to draw
- }
-
- void AGAScrollBarPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->HideSelf(); // make sure the Control Manager object is not drawn
-
- this->CreateAGAObject();
- }
-
- void AGAScrollBarPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGAScrollBarPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGAScrollBarPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGAScrollBarPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGAScrollBarPP::ShowSelf()
- {
- // Suppress showing the Control Manager control.
- }
-
- void AGAScrollBarPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAScrollBar(&bounds, mMinValue, mMaxValue, mValue));
-
- mAGAObject->InstallNotificationRoutine(AGAScrollBarPP::RealAGANotifier, this);
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
- }
-
- void AGAScrollBarPP::SetValue(SInt32 inValue)
- {
- // Set the LStdControl value and the AGA object value.
-
- Inherited::SetValue(inValue);
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- mAGAObject->SetValue(inValue, AGAObject::kRedraw);
- }
- }
-
- void AGAScrollBarPP::SetMinValue(SInt32 inMinValue)
- {
- // Set the LStdControl min and the AGA object min.
-
- Inherited::SetMinValue(inMinValue);
-
- if (mAGAObject != NULL)
- {
- SInt32 oldMin;
- SInt32 oldMax;
-
- this->FocusDraw();
-
- mAGAObject->GetRange(&oldMin, &oldMax);
- mAGAObject->SetRange(inMinValue, oldMax, AGAObject::kRedraw);
- }
- }
-
- void AGAScrollBarPP::SetMaxValue(SInt32 inMaxValue)
- {
- // Set the LStdControl max and the AGA object max.
-
- Inherited::SetMaxValue(inMaxValue);
-
- if (mAGAObject != NULL)
- {
- SInt32 oldMin;
- SInt32 oldMax;
-
- this->FocusDraw();
-
- mAGAObject->GetRange(&oldMin, &oldMax);
- mAGAObject->SetRange(oldMin, inMaxValue, AGAObject::kRedraw);
- }
- }
-
- void AGAScrollBarPP::RealAGANotifier(AGATrackingIndicator* theIndicator, SInt32 dataValue, void* userData)
- {
- // This is a static function. Cast the user data to get
- // the AGAScrollBarMA object, have it handle the notification.
-
- ((AGAScrollBarPP*) userData)->HandleNotification(dataValue);
- }
-
- //
- // AGAScrollerPP ----------------------------------------------------
- //
-
- // === Universal ProcPtrs for Callback functions ===
- static ControlActionUPP sVertSBarAction = nil;
- static ControlActionUPP sHorizSBarAction = nil;
-
- #undef Inherited
- #define Inherited LScroller
-
- AGAScrollerPP* AGAScrollerPP::CreateStream(LStream* inStream)
- {
- return new AGAScrollerPP(inStream);
- }
-
- AGAScrollerPP::AGAScrollerPP(LStream* inStream)
- : Inherited(inStream)
- {
- mOldHorizontalBar = NULL;
- mOldVerticalBar = NULL;
-
- //
- // Back up in the stream so we can find out what the
- // scroll bar indents are.
- //
-
- inStream->SetMarker(-sizeof(SScrollerInfo), streamFrom_Marker);
-
- SScrollerInfo scrollerInfo;
- inStream->ReadData(&scrollerInfo, sizeof(SScrollerInfo));
-
- //
- // Replace the standard scroll bars with AGA scroll bars.
- //
-
- this->MakeCustomScrollBars(scrollerInfo.horizBarLeftIndent,
- scrollerInfo.horizBarRightIndent,
- scrollerInfo.vertBarTopIndent,
- scrollerInfo.vertBarBottomIndent);
- }
-
- AGAScrollerPP::~AGAScrollerPP()
- {
- }
-
- void AGAScrollerPP::FinishCreateSelf()
- {
- Inherited::FinishCreateSelf();
-
- //
- // We can now safely delete the standard scroll bar objects
- // that we have replaced with AGA scroll bars.
- //
-
- if (mOldHorizontalBar != NULL)
- {
- mOldHorizontalBar->Hide();
- delete mOldHorizontalBar;
- mOldHorizontalBar = NULL;
- }
-
- if (mOldVerticalBar != NULL)
- {
- mOldVerticalBar->Hide();
- delete mOldVerticalBar;
- mOldVerticalBar = NULL;
- }
- }
-
- void AGAScrollerPP::MakeCustomScrollBars(
- Int16 inHorizBarLeftIndent,
- Int16 inHorizBarRightIndent,
- Int16 inVertBarTopIndent,
- Int16 inVertBarBottomIndent)
- {
- //
- // NOTE: This code is lifted from LScroller::MakeScrollBars,
- // modified to create our scroll bars of our AGAScrollBarPP class
- // and use our form of notification that supports live scrolling.
- //
-
- SPaneInfo barInfo; // Common information for ScrollBars
- barInfo.visible = false; // ScrollBars aren't visible until
- barInfo.enabled = true; // Scroller is activated
- barInfo.userCon = 0;
- barInfo.superView = this;
-
- mOldHorizontalBar = mHorizontalBar;
-
- mHorizontalBar = nil;
- if (inHorizBarLeftIndent >= 0) {
- // Create Horizontal ScrollBar
- barInfo.paneID = PaneIDT_HorizontalScrollBar;
- barInfo.width = mFrameSize.width - inHorizBarLeftIndent -
- inHorizBarRightIndent;
- barInfo.height = 16;
- barInfo.bindings.left = true;
- barInfo.bindings.right = true;
- barInfo.bindings.top = false;
- barInfo.bindings.bottom = true;
- barInfo.left = inHorizBarLeftIndent;
- barInfo.top = mFrameSize.height - 16;
-
- mHorizontalBar = new AGAScrollBarPP(barInfo, msg_Nothing, 0, 0, 0,
- scrollBarProc, 0, "\p", (Int32) this);
-
- ((AGAScrollBarPP*) mHorizontalBar)->InstallNotificationRoutine(AGAScrollerPP::ScrollBarNotifier, this);
- }
-
- mOldVerticalBar = mVerticalBar;
-
- mVerticalBar = nil;
- if (inVertBarTopIndent >= 0) {
- // Create Vertical ScrollBar
- barInfo.paneID = PaneIDT_VerticalScrollBar;
- barInfo.width = 16;
- barInfo.height = mFrameSize.height - inVertBarTopIndent -
- inVertBarBottomIndent;
- barInfo.bindings.left = false;
- barInfo.bindings.right = true;
- barInfo.bindings.top = true;
- barInfo.bindings.bottom = true;
- barInfo.left = mFrameSize.width - 16;
- barInfo.top = inVertBarTopIndent;
-
- mVerticalBar = new AGAScrollBarPP(barInfo, msg_Nothing, 0, 0, 0,
- scrollBarProc, 0, "\p", (Int32) this);
-
- ((AGAScrollBarPP*) mVerticalBar)->InstallNotificationRoutine(AGAScrollerPP::ScrollBarNotifier, this);
- }
- }
-
- void AGAScrollerPP::HandleNotification(LPane* theScrollBar, SInt32 dataValue)
- {
- // Scroll the image to the new location specified.
- // This is similar to what LScroller does when it listens
- // to a thumb drag message.
-
- SPoint32 newScrollPosition;
-
- mScrollingView->GetScrollPosition(newScrollPosition);
-
- if (theScrollBar == mHorizontalBar)
- newScrollPosition.h = dataValue;
- else if (theScrollBar == mVerticalBar)
- newScrollPosition.v = dataValue;
-
- mScrollingView->ScrollImageTo(newScrollPosition.h, newScrollPosition.v, TRUE);
- this->AdjustScrollBars();
-
- (void) this->FocusDraw(); // scrolling view may have grabbed focus
- }
-
- void AGAScrollerPP::AdjustScrollBars()
- {
- // Check the scrolling view's size compared to ours, so that
- // the scroll bars have to correct page and step sizes.
-
- AGAScrollBarPP* horizontalBar = (AGAScrollBarPP*) mHorizontalBar;
- AGAScrollBarPP* verticalBar = (AGAScrollBarPP*) mVerticalBar;
-
- SPoint32 scrollUnit;
- SDimension16 scrollFrameSize;
- SDimension32 scrollImageSize;
- SPoint32 scrollPosition;
- SPoint32 maxTranslation;
- SPoint32 pageStepSize;
- SPoint32 pageSize;
-
- mScrollingView->GetScrollUnit(scrollUnit);
- mScrollingView->GetFrameSize(scrollFrameSize);
- mScrollingView->GetImageSize(scrollImageSize);
- mScrollingView->GetScrollPosition(scrollPosition);
-
- // The maxTranslation is the max (pinned) scroll value.
- maxTranslation.h = scrollImageSize.width - scrollFrameSize.width;
- maxTranslation.v = scrollImageSize.height - scrollFrameSize.height;
-
- // The page step size is how far to scroll page scrolling
- pageStepSize.h = MaxSInt32(0, scrollFrameSize.width - scrollUnit.h);
- pageStepSize.v = MaxSInt32(0, scrollFrameSize.height - scrollUnit.v);
-
- // The page size is the range that is visible at once.
- // It's not the same as the page step size.
- if (scrollImageSize.width < 1) // avoid divide by zero or weird negatives
- pageSize.h = 1;
- else
- pageSize.h = maxTranslation.h *
- (((float) scrollFrameSize.width) / ((float) scrollImageSize.width));
-
- if (scrollImageSize.height < 1) // avoid divide by zero or weird negatives
- pageSize.v = 1;
- else
- pageSize.v = maxTranslation.v *
- (((float) scrollFrameSize.height) / ((float) scrollImageSize.height));
-
- // Update the scroll bar objects with the calculated values.
-
- if (horizontalBar != NULL)
- {
- horizontalBar->FocusDraw();
- horizontalBar->SetMaxValue(maxTranslation.h);
- horizontalBar->mAGAObject->SetPageSize(pageSize.h, AGAObject::kRedraw);
- horizontalBar->mAGAObject->SetStepSizes(scrollUnit.h, pageStepSize.h);
- horizontalBar->SetValue(scrollPosition.h);
- }
-
- if (verticalBar != NULL)
- {
- verticalBar->FocusDraw();
- verticalBar->SetMaxValue(maxTranslation.v);
- verticalBar->mAGAObject->SetPageSize(pageSize.v, AGAObject::kRedraw);
- verticalBar->mAGAObject->SetStepSizes(scrollUnit.v, pageStepSize.v);
- verticalBar->SetValue(scrollPosition.v);
- }
- }
-
- void AGAScrollerPP::ScrollBarNotifier(LPane* theScrollBar, SInt32 dataValue, void* userData)
- {
- // This is a static function. Cast the user data to get
- // the AGAScrollBarMA object, have it handle the notification.
-
- ((AGAScrollerPP*) userData)->HandleNotification(theScrollBar, dataValue);
- }
-
- //
- // AGASliderPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LControl
-
- AGASliderPP* AGASliderPP::CreateStream(LStream* inStream)
- {
- return new AGASliderPP(inStream);
- }
-
- AGASliderPP::AGASliderPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- mLabelsResourceID = mUserCon; // STR# resource ID of the slider labels (0 for none)
- mLabelsTextTraitsID = -1; // -1 means standard labels style
- mSliderJustification = teFlushDefault;
- }
-
- AGASliderPP::~AGASliderPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGASliderPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGASliderPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGASliderPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGASliderPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGASliderPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGASliderPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- if (mLabelsTextTraitsID == -1)
- ThrowIfNil_(mAGAObject = new AGASlider(&bounds, mMinValue, mMaxValue, mValue, gAGAStdSmallStyle, mLabelsResourceID));
- else
- ThrowIfNil_(mAGAObject = new AGASlider(&bounds, mMinValue, mMaxValue, mValue, AGATextStyle(mLabelsTextTraitsID), mLabelsResourceID));
-
- if (mSliderJustification != teFlushDefault)
- mAGAObject->SetJustification(mSliderJustification);
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- // Slider has to erase when drawing, so make sure that
- // it doesn't assume we're on a gray background.
- RGBColor backColor;
-
- this->FocusDraw();
- this->ApplyForeAndBackColors();
- ::GetBackColor(&backColor);
- mAGAObject->SetBackgroundEraseColor(&backColor);
- }
-
- void AGASliderPP::SetValue(SInt32 inValue)
- {
- // Set the slider value.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- mAGAObject->SetValue(inValue, AGAObject::kRedraw);
- }
- }
-
- void AGASliderPP::SetMinValue(SInt32 inMinValue)
- {
- // Set the slider min.
-
- if (mAGAObject != NULL)
- {
- SInt32 oldMin;
- SInt32 oldMax;
-
- this->FocusDraw();
-
- mAGAObject->GetRange(&oldMin, &oldMax);
- mAGAObject->SetRange(inMinValue, oldMax, AGAObject::kRedraw);
- }
- }
-
- void AGASliderPP::SetMaxValue(SInt32 inMaxValue)
- {
- // Set the slider max.
-
- if (mAGAObject != NULL)
- {
- SInt32 oldMin;
- SInt32 oldMax;
-
- this->FocusDraw();
-
- mAGAObject->GetRange(&oldMin, &oldMax);
- mAGAObject->SetRange(oldMin, inMaxValue, AGAObject::kRedraw);
- }
- }
-
- //
- // AGASliderPPX ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGASliderPP
-
- AGASliderPPX* AGASliderPPX::CreateStream(LStream* inStream)
- {
- return new AGASliderPPX(inStream);
- }
-
- AGASliderPPX::AGASliderPPX(LStream* inStream)
- : Inherited(inStream)
- {
- // Read the labels STR# ID, labels text traits ID, and
- // slider justification from the stream.
-
- inStream->ReadData(&mLabelsResourceID, sizeof(mLabelsResourceID));
- inStream->ReadData(&mLabelsTextTraitsID, sizeof(mLabelsTextTraitsID));
- inStream->ReadData(&mSliderJustification, sizeof(mSliderJustification));
- }
-
- AGASliderPPX::~AGASliderPPX()
- {
- }
-
- //
- // AGALittleArrowsPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LControl
-
- AGALittleArrowsPP* AGALittleArrowsPP::CreateStream(LStream* inStream)
- {
- return new AGALittleArrowsPP(inStream);
- }
-
- AGALittleArrowsPP::AGALittleArrowsPP(LStream* inStream)
- : Inherited(inStream)
- {
- mNotificationRoutine = NULL;
- mAGAObject = NULL;
- mLinkedNumberText = NULL;
- mLinkedPaneID = mUserCon;
- }
-
- AGALittleArrowsPP::~AGALittleArrowsPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGALittleArrowsPP::InstallNotificationRoutine(AGANotifyPPPtr notificationRoutine, void* userData)
- {
- // Save the notification routine fn pointer and user data
- // for notification handling.
-
- mNotificationRoutine = notificationRoutine;
- mUserData = userData;
- }
-
- void AGALittleArrowsPP::HandleNotification(SInt32 deltaValue)
- {
- // Update the linked LEditField, if any, call the
- // installed notification function, and propagate our
- // hot spot result.
-
- if (mLinkedNumberText != NULL)
- {
- SInt32 oldValue = mLinkedNumberText->GetValue();
- SInt32 newValue = oldValue + deltaValue;
-
- // Constrain to our range. Only set new text value if changed.
- newValue = MinSInt32(MaxSInt32(mMinValue, newValue), mMaxValue);
-
- if (newValue != oldValue)
- {
- mLinkedNumberText->SetValue(MinSInt32(MaxSInt32(mMinValue, newValue), mMaxValue));
- mLinkedNumberText->Draw(NULL);
- }
- }
-
- if (mNotificationRoutine != NULL)
- (*mNotificationRoutine)(this, deltaValue, mUserData);
-
- this->HotSpotResult(deltaValue);
-
- this->FocusDraw(); // linked edit field prob'ly grabbed focus
- }
-
- void AGALittleArrowsPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGALittleArrowsPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGALittleArrowsPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGALittleArrowsPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGALittleArrowsPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGALittleArrowsPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGALittleArrows(&bounds));
-
- mAGAObject->InstallNotificationRoutine(AGALittleArrowsPP::RealAGANotifier, this);
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- if (mLinkedPaneID != 0)
- {
- // If you bypass the RTTI here, you must ensure that the
- // pane ID specifies a pane that is a subclass of LEditField.
-
- LPane* linkedPane = mSuperView->FindPaneByID(mLinkedPaneID);
-
- if (linkedPane != NULL)
- {
- #ifndef NO_RTTI
- mLinkedNumberText = dynamic_cast<LEditField*>(linkedPane);
- #else // NO_RTTI
- mLinkedNumberText = (LEditField*) linkedPane;
- #endif // NO_RTTI
-
- if (mLinkedNumberText != NULL)
- mLinkedNumberText->SetValue(mValue);
- }
- }
- }
-
- void AGALittleArrowsPP::RealAGANotifier(AGALittleArrows* theAGAObject, SInt32 deltaValue, void* userData)
- {
- // This is a static function. Cast the user data to get
- // the AGAScrollerScrollBarMA object, have it handle the notification.
-
- ((AGALittleArrowsPP*) userData)->HandleNotification(deltaValue);
- }
-
- //
- // AGALittleArrowsPPX ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited AGALittleArrowsPP
-
- AGALittleArrowsPPX* AGALittleArrowsPPX::CreateStream(LStream* inStream)
- {
- return new AGALittleArrowsPPX(inStream);
- }
-
- AGALittleArrowsPPX::AGALittleArrowsPPX(LStream* inStream)
- : Inherited(inStream)
- {
- // Read the linked LEditField pane ID from the stream.
-
- inStream->ReadData(&mLinkedPaneID, sizeof(mLinkedPaneID));
- }
-
- AGALittleArrowsPPX::~AGALittleArrowsPPX()
- {
- }
-
- //
- // AGAPopupMenuPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LStdPopupMenu
-
- AGAPopupMenuPP* AGAPopupMenuPP::CreateStream(LStream* inStream)
- {
- return new AGAPopupMenuPP(inStream);
- }
-
- AGAPopupMenuPP::AGAPopupMenuPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
-
- // OK, this is really pissing me off, so I shall vent:
- // AGAPopupMenuPP::FinishCreateSelf (not this function) needs
- // to know the popup title width. There are 3 design flaws
- // making our job harder.
- // 1.
- // The big hack also known as the popup CDEF uses the control
- // max as the title width. And once it's inited, the original
- // max value is gone. Now is too late. There is no way to obtain
- // the title width from the CDEF.
- // 2.
- // LStdPopupMenu::InitStdPopupMenu also blows away the original
- // mMaxValue of this pane object. Override, you say. Sorry,
- // InitStdPopupMenu is declared private.
- // 3.
- // Override InitStdControl, you say. Sorry, it's declared non-virtual.
- //
- // So we are stuck with backing up in the stream with hardcoded
- // byte counts, for each superclass, until we get back to the
- // LControl pane data. This is straightforward, but it feels VERY
- // nasty.
-
- SInt32 originalMarker = inStream->GetMarker();
-
- // Undo the LStdPopupMenu stream read.
- inStream->SetMarker(-sizeof(Int16), streamFrom_Marker);
-
- // Undo the LStdControl stream read.
- inStream->SetMarker(-sizeof(Int16), streamFrom_Marker);
- inStream->SetMarker(-sizeof(ResIDT), streamFrom_Marker);
- inStream->SetMarker(-sizeof(Int32), streamFrom_Marker);
- Str255 title;
- ::GetControlTitle(mMacControlH, title);
- inStream->SetMarker(-1 -title[0], streamFrom_Marker);
-
- // Undo the LControl stream read.
- inStream->SetMarker(-sizeof(SControlInfo), streamFrom_Marker);
-
- // Finally, re-read the LControl pane data.
- SControlInfo controlInfo;
- inStream->ReadData(&controlInfo, sizeof(SControlInfo));
-
- mStashedTitleWidth = controlInfo.maxValue; // popup CDEF uses ctl max for width
-
- // And skip forward in the stream so it's back where it
- // was before we touched it, in case a subclass is reading it.
- inStream->SetMarker(originalMarker, streamFrom_Start);
- }
-
- AGAPopupMenuPP::~AGAPopupMenuPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGAPopupMenuPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->HideSelf(); // make sure the Control Manager object is not drawn
-
- this->CreateAGAObject();
- }
-
- void AGAPopupMenuPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGAPopupMenuPP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- {
- this->SetValue(mAGAObject->GetCurrentItemNo());
- //this->BroadcastValueMessage();
- }
- }
- }
-
- void AGAPopupMenuPP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGAPopupMenuPP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGAPopupMenuPP::ShowSelf()
- {
- // Suppress showing the Control Manager control.
- }
-
- void AGAPopupMenuPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- AGAPopupMenu::WidthAdjust widthAdjust;
-
- Rect bounds;
- Str255 title;
- MenuRef theMenuRef = this->GetMacMenuH();
- SInt16 justificationValue = ::GetControlValue(mMacControlH);
-
- if (((mControlKind - popupMenuProc) & popupFixedWidth) != 0)
- widthAdjust = AGAPopupMenu::kFixedWidth;
- else
- widthAdjust = AGAPopupMenu::kSystemMDEFAdjustment;
-
- (void) this->CalcLocalFrameRect(bounds);
- ::GetControlTitle(mMacControlH, title);
-
- ThrowIfNil_(mAGAObject = new AGAPopupMenu(&bounds, mStashedTitleWidth, title, teFlushRight, AGATextStyle(mTextTraitsID), widthAdjust, this->GetMacMenuH(), AGAPopupMenu::kDontDispose));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
- }
-
- void AGAPopupMenuPP::SetValue(SInt32 inValue)
- {
- // Set the actual LStdControl value and the AGA object value.
-
- Inherited::SetValue(inValue);
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetCurrentItemNo(inValue, AGAObject::kRedraw);
- }
- }
-
- //
- // AGADisclosureTrianglePP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LControl
-
- AGADisclosureTrianglePP* AGADisclosureTrianglePP::CreateStream(LStream* inStream)
- {
- return new AGADisclosureTrianglePP(inStream);
- }
-
- AGADisclosureTrianglePP::AGADisclosureTrianglePP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGADisclosureTrianglePP::~AGADisclosureTrianglePP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGADisclosureTrianglePP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGADisclosureTrianglePP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGADisclosureTrianglePP::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- // Let the AGAObject track the mouse.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- if (mAGAObject->TrackMouse(inMouseDown.whereLocal))
- this->HotSpotResult(this->FindHotSpot(inMouseDown.whereLocal));
- }
- }
-
- void AGADisclosureTrianglePP::EnableSelf()
- {
- // Let the AGAObject enable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kEnabled, AGAObject::kRedraw);
- }
- }
-
- void AGADisclosureTrianglePP::DisableSelf()
- {
- // Let the AGAObject disable itself.
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kRedraw);
- }
- }
-
- void AGADisclosureTrianglePP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGADisclosureTriangle(&bounds, AGAObject::kAutomaticState));
-
- if (mEnabled == triState_Off)
- mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
-
- if (mValue == 1) // allow initial state to be set to kDisclosed
- mAGAObject->SetState(AGADisclosureTriangle::kDisclosedState, AGAObject::kDontRedraw);
-
- // Disclosure triangle has to erase when animating, so make sure that
- // it doesn't assume we're on a gray background.
- RGBColor backColor;
-
- this->FocusDraw();
- this->ApplyForeAndBackColors();
- ::GetBackColor(&backColor);
- mAGAObject->SetBackgroundEraseColor(&backColor);
- }
-
- //
- // AGAProgressIndicatorPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LControl
-
- AGAProgressIndicatorPP* AGAProgressIndicatorPP::CreateStream(LStream* inStream)
- {
- return new AGAProgressIndicatorPP(inStream);
- }
-
- AGAProgressIndicatorPP::AGAProgressIndicatorPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGAProgressIndicatorPP::~AGAProgressIndicatorPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGAProgressIndicatorPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGAProgressIndicatorPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGAProgressIndicatorPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAProgressIndicator(&bounds, mMinValue, mMaxValue));
-
- mAGAObject->SetValue(mValue, AGAObject::kDontRedraw);
- }
-
- void AGAProgressIndicatorPP::SetValue(SInt32 inValue)
- {
- // Set the value of the LControl and the AGA object.
-
- Inherited::SetValue(inValue);
-
- if (mAGAObject != NULL)
- {
- this->FocusDraw();
-
- mAGAObject->SetValue(inValue, AGAObject::kRedraw);
- }
- }
-
- void AGAProgressIndicatorPP::SetMinValue(SInt32 inMinValue)
- {
- // Set the min of the LControl and the AGA object.
-
- Inherited::SetMinValue(inMinValue);
-
- if (mAGAObject != NULL)
- {
- SInt32 oldMin;
- SInt32 oldMax;
-
- this->FocusDraw();
-
- mAGAObject->GetRange(&oldMin, &oldMax);
- mAGAObject->SetRange(inMinValue, oldMax, AGAObject::kRedraw);
- }
- }
-
- void AGAProgressIndicatorPP::SetMaxValue(SInt32 inMaxValue)
- {
- // Set the max of the LControl and the AGA object.
-
- Inherited::SetMaxValue(inMaxValue);
-
- if (mAGAObject != NULL)
- {
- SInt32 oldMin;
- SInt32 oldMax;
-
- this->FocusDraw();
-
- mAGAObject->GetRange(&oldMin, &oldMax);
- mAGAObject->SetRange(oldMin, inMaxValue, AGAObject::kRedraw);
- }
- }
-
- //
- // AGAWhiteBackgroundAttachmentPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LAttachment
-
- AGAWhiteBackgroundAttachmentPP* AGAWhiteBackgroundAttachmentPP::CreateStream(LStream* inStream)
- {
- return new AGAWhiteBackgroundAttachmentPP(inStream);
- }
-
- AGAWhiteBackgroundAttachmentPP::AGAWhiteBackgroundAttachmentPP(MessageT inMessage, Boolean inExecuteHost)
- : Inherited(inMessage, inExecuteHost)
- {
- }
-
- AGAWhiteBackgroundAttachmentPP::AGAWhiteBackgroundAttachmentPP(LStream *inStream)
- : Inherited(inStream)
- {
- }
-
- Boolean AGAWhiteBackgroundAttachmentPP::Execute(MessageT inMessage, void *ioParam)
- {
- if (inMessage == msg_DrawOrPrint)
- {
- CleansePen();
-
- // Draw the background in white, inset to avoid the border
- // frame pixels.
-
- Rect paneFrame = *((Rect*) ioParam);
-
- ::RGBForeColor(&gAGARamp[rW]);
- ::InsetRect(&paneFrame, 1, 1);
- ::PaintRect(&paneFrame);
-
- CleansePen();
- }
-
- return TRUE; // owner should also do its work
- }
-
- //
- // AGABorderFrameAttachmentPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LAttachment
-
- AGABorderFrameAttachmentPP* AGABorderFrameAttachmentPP::CreateStream(LStream* inStream)
- {
- return new AGABorderFrameAttachmentPP(inStream);
- }
-
- AGABorderFrameAttachmentPP::AGABorderFrameAttachmentPP(MessageT inMessage, Boolean inExecuteHost)
- : Inherited(inMessage, inExecuteHost)
- {
- }
-
- AGABorderFrameAttachmentPP::AGABorderFrameAttachmentPP(LStream *inStream)
- : Inherited(inStream)
- {
- }
-
- Boolean AGABorderFrameAttachmentPP::Execute(MessageT inMessage, void *ioParam)
- {
- if (inMessage == msg_DrawOrPrint)
- {
- CleansePen();
-
- // Draw the frame with shading outside.
-
- enum { TL, Frame, BR, kNumColors };
-
- UInt8 colorIndex[kNumColors];
-
- // If you bypass the RTTI here, the frame will always
- // draw enabled. (Frankly, you have to look closely to see
- // the difference.)
-
- Boolean ownerEnabled = TRUE;
-
- #ifndef NO_RTTI
- LPane* ownerPane = dynamic_cast<LPane*>(mOwnerHost);
- if (ownerPane != NULL)
- ownerEnabled = ownerPane->IsEnabled();
- #endif // NO_RTTI
-
- GDIterator iter;
- Boolean deep;
-
- while (iter.More(deep))
- {
- Rect paneFrame = *((Rect*) ioParam);
-
- if (deep)
- {
- if (ownerEnabled)
- {
- colorIndex[TL] = r5;
- colorIndex[Frame] = rB;
- colorIndex[BR] = rW;
- }
- else
- {
- colorIndex[TL] = r4;
- colorIndex[Frame] = r10;
- colorIndex[BR] = r1;
- }
- }
- else // 1-bit
- {
- colorIndex[Frame] = rB;
-
- if (! ownerEnabled)
- ::PenPat(&qd.gray);
- }
-
- ::InsetRect(&paneFrame, -1, -1);
-
- if (deep)
- {
- ::RGBForeColor(&gAGARamp[colorIndex[TL]]);
- ::MoveTo(paneFrame.left, paneFrame.bottom - 2);
- ::LineTo(paneFrame.left, paneFrame.top);
- ::LineTo(paneFrame.right - 2, paneFrame.top);
-
- ::RGBForeColor(&gAGARamp[colorIndex[BR]]);
- ::MoveTo(paneFrame.left + 1, paneFrame.bottom - 1);
- ::LineTo(paneFrame.right - 1, paneFrame.bottom - 1);
- ::LineTo(paneFrame.right - 1, paneFrame.top + 1);
- }
-
- ::PenPat(&qd.black);
- }
-
- CleansePen();
- }
-
- return TRUE; // owner should also do its work
- }
-
- //
- // AGAEditFieldPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LEditField
-
- AGAEditFieldPP* AGAEditFieldPP::CreateStream(LStream* inStream)
- {
- return new AGAEditFieldPP(inStream);
- }
-
- AGAEditFieldPP::AGAEditFieldPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Add the attachments that make this edit field AGA-compliant.
-
- this->AddAttachment(new AGAWhiteBackgroundAttachmentPP);
- this->AddAttachment(new AGABorderFrameAttachmentPP);
- }
-
- AGAEditFieldPP::~AGAEditFieldPP()
- {
- }
-
- void AGAEditFieldPP::DrawBox()
- {
- // NOTE: THIS FIRST SECTION IS LIFTED VERBATIM FROM LEditField::DrawBox
-
- // Box around an EditField is outset from the Text by 2 pixels.
- // The box itself is 1 pixel thick, drawn in the foreground color
- // of the Pane (not necessarily the same as the text color). If
- // the EditField is disabled, the box draws with a gray pattern.
- //
- // The 1 pixel rectangle between the box and the text draws in
- // the background color of the text.
-
- StColorState saveColors; // Preserve color state
- Rect frame;
- CalcLocalFrameRect(frame);
- ::PenNormal();
-
- // Draw empty area between Box and Text. On entry, the fore
- // and back colors for the Text are in effect (as set in FocusDraw).
- // Use Text back color as the fore color for the empty area.
-
- ::InsetRect(&frame, 1, 1);
- RGBColor emptyColor;
- ::GetBackColor(&emptyColor);
- ::RGBForeColor(&emptyColor);
- ::FrameRect(&frame);
-
- // Draw border around EditField
-
- ::InsetRect(&frame, -1, -1);
-
- // REMAINING CODE PERFORMS PROPER GRAYSCALE DIMMING:
-
- GDIterator iter;
- Boolean deep;
-
- while (iter.More(deep))
- {
- if (deep)
- {
- ::PenPat(&qd.black);
-
- if (mEnabled == triState_Off)
- ::RGBForeColor(&gAGARamp[r10]);
- else
- ::RGBForeColor(&gAGARamp[rB]);
- }
- else
- {
- ::RGBForeColor(&gAGARamp[rB]);
-
- if (mEnabled == triState_Off)
- ::PenPat(&qd.gray);
- else
- ::PenPat(&qd.black);
- }
-
- ::FrameRect(&frame);
- }
- }
-
- //
- // AGATextEditPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LTextEdit
-
- AGATextEditPP* AGATextEditPP::CreateStream(LStream* inStream)
- {
- return new AGATextEditPP(inStream);
- }
-
- AGATextEditPP::AGATextEditPP(LStream* inStream)
- : Inherited(inStream)
- {
- // Add the attachments that make this edit field AGA-compliant.
-
- this->AddAttachment(new AGAWhiteBackgroundAttachmentPP);
- this->AddAttachment(new AGABorderFrameAttachmentPP);
- }
-
- AGATextEditPP::~AGATextEditPP()
- {
- }
-
- //
- // AGASeparatorPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LPane
-
- AGASeparatorPP* AGASeparatorPP::CreateStream(LStream* inStream)
- {
- return new AGASeparatorPP(inStream);
- }
-
- AGASeparatorPP::AGASeparatorPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGASeparatorPP::~AGASeparatorPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGASeparatorPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGASeparatorPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGASeparatorPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGASeparator(&bounds));
- }
-
- //
- // AGACaptionPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LCaption
-
- AGACaptionPP* AGACaptionPP::CreateStream(LStream* inStream)
- {
- return new AGACaptionPP(inStream);
- }
-
- AGACaptionPP::AGACaptionPP(LStream* inStream)
- : Inherited(inStream)
- {
- mAGAObject = NULL;
- }
-
- AGACaptionPP::~AGACaptionPP()
- {
- // Delete AGA object if we successfully allocated it.
-
- if (mAGAObject != NULL)
- delete mAGAObject;
- }
-
- void AGACaptionPP::FinishCreateSelf()
- {
- // Create and set up the AGAObject.
-
- this->CreateAGAObject();
- }
-
- void AGACaptionPP::DrawSelf()
- {
- // Let the AGAObject draw itself.
-
- if (mAGAObject != NULL)
- mAGAObject->DrawObject();
- }
-
- void AGACaptionPP::SetDescriptor(ConstStringPtr inDescriptor)
- {
- Inherited::SetDescriptor(inDescriptor);
-
- // Install the new text in the AGA object. Don't tell it
- // to redraw; the redraw comes from the caller.
-
- Str255 newText;
- this->GetDescriptor(newText);
- mAGAObject->SetTitle(newText, AGAObject::kDontRedraw);
- }
-
- void AGACaptionPP::SetValue(SInt32 inValue)
- {
- Inherited::SetValue(inValue);
-
- // Install the new text in the AGA object. Don't tell it
- // to redraw; the redraw comes from the caller.
-
- Str255 newText;
- this->GetDescriptor(newText);
- mAGAObject->SetTitle(newText, AGAObject::kDontRedraw);
- }
-
- void AGACaptionPP::CreateAGAObject()
- {
- // Instantiate the particular AGAObject subclass.
-
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ThrowIfNil_(mAGAObject = new AGAStaticText(&bounds, AGATextStyle(mTxtrID), GetTextTraitsJustification(mTxtrID)));
-
- this->SetDescriptor(mText); // make sure AGA object text is inited
- }
-
- //
- // AGAFocusBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LFocusBox
-
- AGAFocusBoxPP* AGAFocusBoxPP::CreateStream(LStream* inStream)
- {
- return new AGAFocusBoxPP(inStream);
- }
-
- AGAFocusBoxPP::AGAFocusBoxPP()
- : Inherited()
- {
- }
-
- AGAFocusBoxPP::AGAFocusBoxPP(const LFocusBox &inOriginal)
- : Inherited(inOriginal)
- {
- }
-
- AGAFocusBoxPP::AGAFocusBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- }
-
- AGAFocusBoxPP::~AGAFocusBoxPP()
- {
- }
-
- void AGAFocusBoxPP::DrawSelf()
- {
- // Draw the AGA-style focus frame.
-
- GDIterator iter;
- Boolean deep;
-
- RgnHandle borderRegion = ::NewRgn();
-
- while (iter.More(deep))
- {
- if (deep)
- ::RGBForeColor(&gAGARamp[r8]);
- else
- ::RGBForeColor(&gAGARamp[rB]);
-
- this->ComputeBorderRegion(borderRegion);
- PaintRgn(borderRegion);
- }
-
- ::DisposeRgn(borderRegion);
- }
-
- void AGAFocusBoxPP::ComputeBorderRegion(RgnHandle borderRegion)
- {
- // Compute the border region to be painted.
-
- RgnHandle innerRegion = ::NewRgn();
- Rect bounds;
-
- (void) this->CalcLocalFrameRect(bounds);
-
- ::OpenRgn();
- ::FrameRoundRect(&bounds, 4, 4);
- ::CloseRgn(borderRegion);
-
- ::InsetRect(&bounds, 2, 2);
- ::RectRgn(innerRegion, &bounds);
- ::DiffRgn(borderRegion, innerRegion, borderRegion);
-
- ::DisposeRgn(innerRegion);
- }
-
- //
- // AGAListBoxPP ----------------------------------------------------
- //
-
- #undef Inherited
- #define Inherited LListBox
-
- AGAListBoxPP* AGAListBoxPP::CreateStream(LStream* inStream)
- {
- return new AGAListBoxPP(inStream);
- }
-
- AGAListBoxPP::AGAListBoxPP(LStream* inStream)
- : Inherited(inStream)
- {
- }
-
- AGAListBoxPP::~AGAListBoxPP()
- {
- }
-
- void AGAListBoxPP::FinishCreateSelf()
- {
- // Replace the standard LFocusBox with an AGAFocusBoxPP
- // initialized from the existing one.
-
- if (mFocusBox != NULL)
- {
- AGAFocusBoxPP* newFocusBox = new AGAFocusBoxPP(*mFocusBox);
-
- delete mFocusBox;
-
- mFocusBox = newFocusBox;
- mFocusBox->AttachPane(this, FALSE);
-
- // The standard LFocusBox is smaller by 1 pixel on each
- // side than the AGA focus box, so expand ours from where
- // LFocusBox::AttachPane located and sized it.
-
- mFocusBox->MoveBy(-1, -1, TRUE);
- mFocusBox->ResizeFrameBy(2, 2, TRUE);
- }
-
- // Attach the white background and border frame attachments.
-
- this->AddAttachment(new AGAWhiteBackgroundAttachmentPP);
- this->AddAttachment(new AGABorderFrameAttachmentPP);
- }
-
-